SRC=./src
CFLAGS= -ansi  -pedantic-errors -Wall -Werror 
CFLAGS= -D _GNU_SOURCE
COMPILEONLY= -c 
BIN=bin
OBJ=obj
CM=Common
PB=Public
ST=Static
DN=Dinamic
RL=../$(CM)/$(BIN)/Release

CC=gcc

Debug:   Debug_OR_Release=Debug
Debug:   CFLAGS+=-g 
Debug:   SUBDIRS= ./$(OBJ)/$(Debug_OR_Release) ./$(BIN)/$(Debug_OR_Release)
Debug:   OBJ_F=$(OBJ)/$(Debug_OR_Release)/iterbintreeKM.o

Release: Debug_OR_Release=Release
Release: CFLAGS+=-DNDEBUG -O2
Release: SUBDIRS= ./$(OBJ)/$(Debug_OR_Release) ./$(BIN)/$(Debug_OR_Release)
Release: OBJ_F=$(OBJ)/$(Debug_OR_Release)/iterbintreeKM.o



all: Release

Debug:   create_folders  BinaryTree Install cleanDebug 
Release: create_folders  BinaryTree Install cleanRelease




BinaryTree: show_action  Bittree.object 
	ar -rs  ./$(BIN)/$(Debug_OR_Release)/iterbintreeKM.a  $(OBJ_F)   

show_action:
	@echo
	@echo "-----------------------------------"
	@echo "   PRODUCING Binary Tree Library  "
	@echo "-----------------------------------"
	@echo



Bittree.object: $(SRC)/iterbintreeKM.c $(SRC)/iterbintreeKM.h
	$(CC)  $(CFLAGS) -I $(SRC) -I ../$(CM)/$(PB)  $(SRC)/iterbintreeKM.c $(COMPILEONLY) -o $(OBJ_F)
 
create_folders:
	mkdir -p $(OBJ)/$(Debug_OR_Release) 
	mkdir -p $(BIN)/$(Debug_OR_Release)

Install:creat_instal_folders CopyF CopyHfile 


CopyF: 
	cp $(BIN)/$(Debug_OR_Release)/iterbintreeKM.a   ../$(CM)/$(BIN)/$(Debug_OR_Release)

CopyHfile:
	cp $(SRC)/iterbintreeKM.h ../Common/$(PB)
		
creat_instal_folders:
	mkdir -p ../$(CM)/$(PB)
	mkdir -p ../$(CM)/$(BIN)/$(Debug_OR_Release)


cleanDebug:
	for i in $(SUBDIRS); do\
		(cd $$i; rm -f * );\
	done
	rm -f ./*.o
	rm -r $(BIN)
	rm -r $(OBJ)

cleanRelease:
	for i in $(SUBDIRS); do\
		(cd $$i; rm * );\
	done
	rm -f ./*.o
	rm -r $(BIN)
	rm -r $(OBJ)

